package android.app.show;

import android.content.Context;
import android.widget.Toast;
/**
 * Toast显示
 * @author Administrator
 *
 */
public class Activity extends android.app.log.Activity{
	 private static String oldMsg;  
	    protected static Toast toast   = null;  
	    private static long oneTime=0;  
	    private static long twoTime=0;  
	    /**
	     * 显示不等待的Toast：Toast没消失时候，文字内容相同不显示；文字内容不同直接替换文字，重新显示Toast。
	     * @param message
	     */
	    public void showToast(String message){      
	        if(toast==null){   
	            toast =Toast.makeText(this, message, Toast.LENGTH_SHORT);  
	            toast.show();  
	            oneTime=System.currentTimeMillis();  
	        }else{  
	            twoTime=System.currentTimeMillis();  
	            if(message.equals(oldMsg)){  
	                if(twoTime-oneTime>Toast.LENGTH_SHORT){  
	                    toast.show();  
	                }  
	            }else{  
	                oldMsg = message;  
	                toast.setText(message);  
	                toast.show();  
	            }         
	        }  
	        oneTime=twoTime;  
	    } 
	    /**
	     * 显示普通的Toat并输出日志
	     */
	    public void Toast(String msg){
	    	Toast.makeText(this, msg,Toast.LENGTH_LONG).show();
	    	i("Toast "+msg);
	    }
	    /**
	     * 显示不等待的Toast同时输出日志
	     * @param msg
	     */
	    public void show(String msg){
	    	showToast(msg);
	    	e("Toast "+msg);
	    }
	    public  void show(int resId){
	    	showToast(this.getString(resId));
	    	e("Toast "+this.getString(resId));
	    }
	    
	    public void showToastInThread(final Activity context,final String msg){
			context.runOnUiThread(new Runnable(){
				@Override
				public void run() {
					Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
				}
			});
		}
}
